package com.example.service.webhook.business.alipay.repository;

import com.example.service.webhook.business.alipay.entity.AlipayContactInfoEntity;
import com.example.service.webhook.business.alipay.entity.AlipayRecentTraderInfoEntity;
import com.example.service.webhook.repository.base.BaseDAO;
import com.example.service.webhook.util.DateUtil;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * @author liyang
 * @email liyang@51dojo.com
 * @create 2017-10-23 下午2:57
 * @description t_alipay_recenttraderinfo
 **/
@Repository
public class AlipayRecentTraderInfoRepository extends BaseDAO<AlipayRecentTraderInfoEntity> {

    @Resource(name = "templateAlipay")
    private JdbcTemplate jdbcTemplate;

    public JdbcTemplate getJdbcTemplate() {
        return jdbcTemplate;
    }

    public void saveRecentTraderInfo(AlipayRecentTraderInfoEntity entity) throws Exception {
        entity.setCreateTime(DateUtil.getCurrentDate());
        entity.setLastModifyTime(DateUtil.getCurrentDate());
        this.add(entity);
    }


    public void updateRecentTraderInfo(AlipayRecentTraderInfoEntity entity) throws Exception {
        entity.setLastModifyTime(DateUtil.getCurrentDate());
        this.modify(entity);
    }


    public AlipayRecentTraderInfoEntity getRecentTraderInfo(String userId, String mappingId, String realName) throws Exception {
        String sql = "";
        String tableName = "t_alipay_recent_trader";
        sql = "select * from " + tableName + " where userId=? and mappingId=? and realName=?";
        AlipayRecentTraderInfoEntity pojo = null;
        try {
            pojo = (AlipayRecentTraderInfoEntity) queryOne(sql, new Object[]{userId, mappingId, realName}, new AlipayRecentTraderInfoEntity());
        } catch (EmptyResultDataAccessException e) {
            return null;
        }

        return pojo;
    }
}
